<template>
  <a-card :bordered="false">

    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">

          <a-col :md="6" :sm="12">
            <a-form-item label="品类">
              <a-select
                v-model="queryParam.category"
                style="width: 150px"
                @focus="focus"
                ref="select"
                @change="handleChange"
                placeholder="请选择品类"
              >
                <a-select-option v-for="(item,key) in categoryList" :key="item.id">
                  {{ item.category_name }}
                </a-select-option>
              </a-select>
            </a-form-item>
          </a-col>

          <a-col :md="6" :sm="12">
            <a-form-item label="业务类型">
              <a-select
                style="width: 120px"
                ref="select"
                placeholder="选择业务类型"
                v-model="queryParam.businessType"
              >
                <a-select-option value="0">
                  个定定制
                </a-select-option>
                <a-select-option value="1">
                  团体定制
                </a-select-option>
                <a-select-option value="2">
                  标码加工
                </a-select-option>
              </a-select>
            </a-form-item>
          </a-col>

          <a-col :md="6" :sm="8">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <!--<a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>-->
            </span>
          </a-col>

        </a-row>
      </a-form>
    </div>

    <!-- 操作按钮区域 -->

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i>已选择&nbsp;<a style="font-weight: 600">{{
          selectedRowKeys.length
        }}</a>项&nbsp;&nbsp;
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        bordered
        size="middle"
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange">

        <template slot="avatarslot" slot-scope="text, record, index">
          <div class="anty-img-wrap">
            <a-avatar shape="square" :src="getAvatarView(record.avatar)" icon="user"/>
          </div>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="$router.push({path:'/storeCenter/SetDegress',query:{id:record.id,category:record.categoryId}})">设置售价加价</a>
          <a-popconfirm style="margin-left: 10px" title="确定删除吗?"
                        @confirm="() => delPriceCFunc(record.id)">
                    <a type="primary">删除</a>
                  </a-popconfirm>
        </span>


      </a-table>
    </div>
    <!-- table区域-end -->
  </a-card>
</template>

<script>
import {JeecgListMixin} from '@/mixins/JeecgListMixin'
import JInput from '@/components/jeecg/JInput'
import {getAction} from "../../api/manage";

export default {
  mixins: [JeecgListMixin],
  components: {
    JInput,
  },
  data() {
    return {
      description: '这是新增装箱单',
      boxName: '', // 装箱单名称
      remark: '', // 备注
      queryParam: {},
      recycleBinVisible: false,
      productList: [], // 产品列表
      columns: [
        {
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          sorter: true,
          align: "center",
          customRender: function (t, r, index) {
            return parseInt(index) + 1;
          }
        },
        {
          title: '品类',
          align: "center",
          dataIndex: 'categoryName',
          width: 120,
          sorter: true
        },
        {
          title: '业务类型',
          align: "center",
          width: 80,
          dataIndex: 'businessType',
          sorter: true,
          customRender: function (text) {
            if (text == '0') {
              return '个定定制'
            } else if (text == '1') {
              return '团体定制'
            } else if (text == '2') {
              return '标码加工'
            }
          }
        },
        /*{
          title: '工艺类型',
          align: "center",
          width: 100,
          dataIndex: 'customerCode'
        },*/
        {
          title: '新增时间',
          align: "center",
          width: 100,
          dataIndex: 'createTime'
        },
        {
          title: '状态',
          align: "center",
          width: 100,
          dataIndex: 'status',
          customRender: function (text) {
            if (text == '0') {
              return '未设置'
            } else if (text == '2') {
              return '已设置'
            }
          }
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          width: 100,
          scopedSlots: {customRender: 'action'}
        }

      ],
      url: {
        list: "/degression/listPrice", // 数据列表
        delPriceC: "/degression/delPriceC", // 删除成本
        pingleilist: "/Discount/getallcategory", // 品类列表
      },
    }
  },
  created() {
    this.getallcategory();
  },
  methods: {

    /**
     * 删除成本
     */
    delPriceCFunc(id) {
      getAction(this.url.delPriceC, {'id': id}).then((res) => {
        if (res.code == 200) {
          this.loadData()
          this.$message.success("操作成功")
        } else {
          this.$message.warning("操作失败")
        }
      })
    },

    //查询所有品类
    getallcategory() {
      getAction(this.url.pingleilist).then((res) => {
        if (res.success) {

          this.categoryList = res.result;
          console.log("没有值吗" + this.categoryList[0].category_name);
        } else {
          that.$message.warning(res.message);
        }
      })
    },
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less'
</style>